import Vue from 'vue';
import Vuex from 'vuex';
Vue.use(Vuex);

const store = new Vuex.Store({
	state: {
		isAlreadyLogin: true,
		openId: "",
		sessionId: undefined,
		autor: {
			"clientId": "1",
			"name": "测试客户",
			"sex": true,
			"headImg": "",
			"openId": "adf",
		},
		location: undefined,
		locationFlg: false,
		requestOption: undefined,
		rvideos: "[]",
	},
	mutations: {
		setRvideo(state, rvideos) {
			state.rvideos = rvideos;
		},
		removeRvideo(state) {
			state.rvideos = "[]";
		},
		setLocation(state, location) {
			state.location = location;
			state.locationFlg = true;
		},
		removeLocation(state) {
			state.location = undefined;
			state.locationFlg = false;
		},
		setRequestOption(state, requestOption) {
			state.requestOption = requestOption;
			state.sessionId = undefined;
		},
		removeRequestOption(state) {
			state.requestOption = undefined;
		},
		removeSessionId(state) {
			state.sessionId = "";
		},
		setSessionId(state, sessionId) {
			state.sessionId = sessionId;
		},
		saveOpenId(state, openId) {
			state.openId = openId;
		},
		loginSuccess(state, autor) {
			state.isAlreadyLogin = true;
			state.autor = autor;
			
			if (state.requestOption) {
				state.requestOption.header["Cookie"] = "JSESSIONID="+state.sessionId;
				uni.request(state.requestOption);
				state.requestOption = undefined;
			}
		},
		loginOut(state) {
			state.isAlreadyLogin = false;
			state.autor = undefined;
		},
		closeScroll() {
			document.querySelector('body').setAttribute("style", "overflow:hidden;");
		},
		openScroll() {
			document.querySelector('body').removeAttribute("style");
		},
		
	}
});
export default store;